package com.turnengine.client.global.user.command;

import com.javabi.command.IExecutableCommand;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.serializer.AbstractCommandDataSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * The Get User Names Data Serializer.
 */
public class GetUserNamesDataSerializer extends AbstractCommandDataSerializer<List<String>> implements IGetUserNamesDataSerializer {

	/**
	 * Creates a new Get User Names Data Serializer.
	 */
	public GetUserNamesDataSerializer() {
		super(GetUserNames.COMMAND_ID);
	}

	@Override
	public List<String> readReturnValue(IDataReader reader) throws IOException {
		List<String> value = reader.readStringList(true, false);
		return value;
	}

	@Override
	public void writeReturnValue(IDataWriter writer, List<String> value) throws IOException {
		writer.writeStringList(value, true, false);
	}

	@Override
	public IExecutableCommand<List<String>> readRequest(IDataReader reader) throws IOException {

		// Read fields
		long loginId = reader.readLong();

		// Create object
		GetUserNames object = new GetUserNames();
		object.setLoginId(loginId);
		return object;
	}

	@Override
	public void writeRequest(IDataWriter writer, IExecutableCommand<List<String>> argument) throws IOException {
		GetUserNames object = (GetUserNames) argument;

		// Get fields
		long loginId = object.getLoginId();

		// Write fields
		writer.writeLong(loginId);
	}

	@Override
	public IExecutableCommandResponse<List<String>> newResponse() {
		return new GetUserNamesResponse();
	}
}
